"""Build objects"""
import daos_build
Import('env', 'prereqs')

def scons():
    """Execute build"""

    env.AppendUnique(LIBPATH=[Dir('.')])

    denv = env.Clone()
    prereqs.require(denv, 'argobots', 'protobufc', 'hwloc')

    # Common object code
    common_tgts = denv.SharedObject(['obj_class.c', 'obj_rpc.c', 'obj_task.c',
                                     'obj_utils.c', 'rpc_csum.c', 'obj_tx.c',
                                     'obj_enum.c', 'obj_class_def.c'])

    # Object client library
    dc_obj_tgts = denv.SharedObject(['cli_obj.c', 'cli_shard.c',
                                     'cli_mod.c', 'cli_ec.c',
                                     'obj_verify.c'])
    dc_obj_tgts += common_tgts
    Export('dc_obj_tgts')

    if not prereqs.server_requested():
        return

    # generate server module
    senv = denv.Clone()
    prereqs.require(senv, 'pmdk', headers_only=True)

    senv.Append(CPPDEFINES=['-DDAOS_PMEM_BUILD'])
    srv = daos_build.library(senv, 'obj',
                             common_tgts + ['srv_obj.c', 'srv_mod.c',
                                            'srv_obj_remote.c', 'srv_ec.c',
                                            'srv_csum.c', 'srv_obj_migrate.c',
                                            'srv_cli.c', 'srv_ec_aggregate.c'],
                             install_off="../..")
    senv.Install('$PREFIX/lib64/daos_srv', srv)

    if prereqs.test_requested():
        SConscript('tests/SConscript', exports='denv')

if __name__ == "SCons.Script":
    scons()
